package com.springboot.controller;

import com.springboot.common.resolver.MyRequestParam;
import com.springboot.model.Student;
import com.springboot.model.convert.Order;
import com.springboot.model.convert.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;

/**
 * @Author: TongRui乀
 * @Date: 2020-04-12 15:13
 * @description：
 */
@Slf4j
@RestController
@RequestMapping("convert")
public class WebConvertController {


    @PostMapping("setUser")
    public String setUser(@MyRequestParam User user){

      log.info("userInfo:{}", user);

      return "SUCCESS";
    }


    @GetMapping("getUserInfo")
    public User getUserInfo(){

        User user = new User();

        user.setId("1");
        user.setCreateTime(new Date());
        user.setName("rose");

        ArrayList<Order> orders = new ArrayList<>();

        Order o1 = new Order();

        o1.setId("1");
        o1.setOrderNumber("11");
        o1.setOrderTime(new Date());

        Order o2 = new Order();

        o2.setId("2");
        o2.setOrderNumber("2");
        o2.setOrderTime(new Date());

        orders.add(o1);
        orders.add(o2);

        user.setOrders(orders);

        return user;
    }


    @PostMapping(value = "student", consumes = "text/properties;charset=utf-8")
    public Properties student(@RequestBody Properties student){
        return student;
    }
}
